<?php

function dec_to_hex($dec) {
    $sign = ""; // suppress errors 
    $h = "";
    if ($dec < 0) {
        $sign = "-";
        $dec = abs($dec);
    }

    $hex = Array(0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5,
        6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 'a',
        11 => 'b', 12 => 'c', 13 => 'd', 14 => 'e',
        15 => 'f');

    do {
        $h = $hex[($dec % 16)] . $h;
        $dec /= 16;
    } while ($dec >= 1);

    return $h;
}

echo "<table border = 2>";
for ($r = 0; $r < 255; $r+=50) {
    echo "<tr>";
    for ($g = 0; $g < 255; $g+=50) {
        echo "<tr>";
        for ($b = 0; $b < 255; $b+=50) {
            echo "<td>";
            $red = dec_to_hex($r);
            $green = dec_to_hex($g);
            $blue = dec_to_hex($b);
            echo "<font color = #" . $red . $green . $blue . ">" . $red . $green . $blue . "</font>";
            echo "</td>";
        }echo "</tr>";
    }echo "</tr>";
}echo "</table>";
?>
